package com.gee.spring.boot.influxdb.core.query.segment;

import java.util.ArrayList;
import java.util.stream.Collectors;

import static com.gee.spring.boot.influxdb.core.constant.StrConstant.*;
import static com.gee.spring.boot.influxdb.core.enums.SqlKeyword.ORDER_BY;

/**
 * @author gepengjun
 * @since 2024/4/29 8:28
 */
public class OrderBySegmentList extends ArrayList<OrderBySegment> implements ISqlSegment {
    private static final long serialVersionUID = -8181999778217434693L;

    @Override
    public String getSqlSegment() {
        if (size() > 0){
            return ORDER_BY.getKeyword() + SPACE + stream().map(OrderBySegment::getSqlSegment).collect(Collectors.joining(COMMA));
        }
        return EMPTY;
    }
}
